package com.hqully.labmanage.controller;

import com.github.pagehelper.PageInfo;
import com.hqully.labmanage.domain.dto.PageDTO;
import com.hqully.labmanage.domain.dto.StuInfoDTO;
import com.hqully.labmanage.domain.vo.ResultVO;
import com.hqully.labmanage.domain.vo.StuInfoTree;
import com.hqully.labmanage.service.StuInfoService;
import com.hqully.labmanage.utils.ResultVOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 学籍信息数据接口
 * <p>
 *
 * @author hqully
 * @version 1.0
 * @date 2022-10-10 19:43:53
 */
@Api(tags = {"学籍信息数据接口"})
@Slf4j
@RestController
@RequestMapping("/api/stu-info")
public class StuInfoController extends BaseController {

    @Resource
    private StuInfoService stuInfoService;

    @ApiOperation(value = "获取学生学籍信息树")
    @GetMapping("/get-info-tree")
    public ResultVO<StuInfoTree> getInfoTree(String code) {
        StuInfoTree infoTree = stuInfoService.getInfoTree(code);
        return ResultVOUtil.success(infoTree);
    }

    @ApiOperation(value = "分页条件查询学籍信息列表")
    @GetMapping("/page-stu-infos")
    public ResultVO<PageInfo<StuInfoDTO>> pageStuInfos(PageDTO page, StuInfoDTO stuInfoDTO) {
        PageInfo<StuInfoDTO> stuInfoPage = stuInfoService.pageStuInfos(page, stuInfoDTO);
        return ResultVOUtil.success(stuInfoPage);
    }

    @ApiOperation(value = "条件查询学籍信息列表")
    @GetMapping("/list-stu-infos")
    public ResultVO<List<StuInfoDTO>> listStuInfos(StuInfoDTO stuInfoDTO) {
        List<StuInfoDTO> stuInfoList = stuInfoService.listStuInfos(stuInfoDTO);
        return ResultVOUtil.success(stuInfoList);
    }

    @ApiOperation(value = "添加学籍信息")
    @PostMapping("/add-stu-info")
    public ResultVO<StuInfoDTO> addStuInfo(@Validated @RequestBody StuInfoDTO stuInfoDTO) {
        stuInfoService.addStuInfo(stuInfoDTO);
        return ResultVOUtil.success("添加学籍信息成功");
    }

    @ApiOperation(value = "更新学籍信息")
    @PostMapping("/update-stu-info")
    public ResultVO<StuInfoDTO> updateStuInfo(@Validated @RequestBody StuInfoDTO stuInfoDTO) {
        stuInfoService.updateStuInfo(stuInfoDTO);
        return ResultVOUtil.success("更新学籍信息成功");
    }

    @ApiOperation(value = "删除学籍信息")
    @DeleteMapping("/delete-stu-info/{id}")
    public ResultVO<StuInfoDTO> deleteStuInfo(@PathVariable("id") Integer id) {
        stuInfoService.deleteStuInfoById(id);
        return ResultVOUtil.success("删除学籍信息成功");
    }

}

